<template>
  <div>
    <div class="head">
      <a @click="$router.push({path: '/ForMy'})" class="return"></a>
      {{$t('MyDividend.v1')}}
    </div>
    <div class="overlay">
      <div class="overlay-content scrolling" style="padding-top:10px;">
        <div style="background: white;">
          <div style="font-size: 34px;color: rgb(34, 167, 123);padding-top: 40px;padding-bottom: 20px;" align="center"
               v-text="parseFloat(Number(sum)).toFixed(5).slice(0,-1)">
            125
          </div>
          <div style="font-size: 13px;padding-top: 20px;padding-bottom: 10px;padding-left: 10px;padding-right: 10px;">
            <van-row>
              <van-col span="12" style="text-align: left;color: rgb(125, 126, 128);">
                <span>{{$t('MyDividend.v2')}}:</span>
                <span v-text="parseFloat(Number(sum)).toFixed(5).slice(0,-1)">125</span>
              </van-col>
              <van-col span="12" style="text-align: right;">
                <span style="color: rgb(125, 126, 128);">{{$t('MyDividend.v3')}}:</span>
                <span style="color: rgb(60, 167, 109);">EXUU</span>
              </van-col>
            </van-row>
          </div>
        </div>
        <div style="padding: 15px 10px;background: white;margin-top: 10px;">
          {{$t('MyDividend.v4')}}
        </div>
        <div style="padding: 15px 10px;">
          {{$t('MyDividend.v5')}}
        </div>
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh" pulling-text=" " :loosing-text="$t('MyTeam.v8')"
                          :loading-text="$t('MyTeam.v7')">
          <van-list v-model="loading" :finished="finished" :finished-text="$t('Prize.v3')"
                    :loading-text="$t('MyTeam.v7')" @load="onLoad">
            <div
              style="padding: 15px 10px;background: white;font-size: 13px;color: rgb(125, 126, 128);margin-bottom: 10px;"
              v-for="(item,index) in list" :key="item.index">
              <van-row>
                <van-col span="10" style="text-align: left;">
                  {{item.createTime | dateFormat}}
                </van-col>
                <van-col span="14" style="text-align: right;">
                  {{item.title}}
                  <div style="color: rgb(249, 73, 81);">
                    +{{parseFloat(Number(item.num)).toFixed(5).slice(0,-1)}}
                  </div>
                </van-col>
              </van-row>
            </div>
          </van-list>
        </van-pull-refresh>
      </div>
    </div>
  </div>
</template>

<script>
    import {crowdfunding} from './../../utils/api';
    import {dateFormat} from 'vux';

    export default {
        name: "MyDividend",
        data() {
            return {
                list: [],
                size: 10, // 每页数量
                current: 1,
                total: '', // 总数量
                listLength: '', //当前总数量
                isLoading: false,
                finished: false,
                loading: false,
                sum: ''
            };
        },
        methods: {
            getList() {
                crowdfunding.getShare({
                    current: this.current,
                    size: this.size
                }).then(res => {
                    if (res.code == 200) {
                        this.sum = res.data.sum;
                        this.list = res.data.iPage.records;
                        this.listLength = res.data.iPage.records.length;
                        this.total = res.data.iPage.total;
                        if (this.total > this.listLength) {
                            this.size += 10;
                            this.loading = false;
                        } else {
                            // 加载状态结束
                            this.finished = true;
                            this.loading = false;
                        }
                    }
                })
            },
            onRefresh() { // 下拉刷新
                this.getList();
                setTimeout(() => {
                    this.$toast({
                        duration: 800,
                        message: this.$t('Prize.v23')
                    });
                    this.isLoading = false;
                }, 500);
            },
            onLoad() { // 上拉加载
                this.getList();
            }
        },
        filters: {
            dateFormat
        }
    }
</script>

<style lang="less" scoped>
  .overlay {
    background: rgb(245, 245, 245);
    color: black;
  }

  .head {
    background: white;
    color: black;
  }

  .head .return:after {
    border-color: #000;
  }
</style>
